import React from 'react';
import { inject, observer } from 'mobx-react';
import { Modal } from 'antd';
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
import CptShowGroup from '../comp/cpt-show-group'
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@inject('cptInstockCheckStore')
@observer
class CheckLisk extends React.Component {
    constructor(props) {
		super(props);
	}

   
    componentWillReceiveProps(nextProps){

    }
    render(){
        const {cptInstockCheckStore} = this.props;
        const {checkTableStore,showDetail,showInstockCheckInfo} = cptInstockCheckStore;
        return (<div >
           <CptShowGroup ecId={`${this && this.props && this.props.ecId || ''}_CptShowGroup@1fy7bu`}
                leftComponent={getLabel(83689,"待验收入库单")}
                rightComponent={[]}
            >
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@o4nidk`} 
                    comsWeaTableStore={checkTableStore}
                    hasOrder={true}
                    needScroll={true}
                    getColumns={c=>this.reRenderColumns(c)}
                    onOperatesClick={this.onOperatesClick.bind(this)}
                />
            </CptShowGroup>
            
        </div>)

    }
    onOperatesClick(record,index,operate,flag){
        const {cptInstockCheckStore} = this.props;
        if(flag == "0"){ //验收
            cptInstockCheckStore.showInstockCheckInfo(true,{ 'instockid': record.randomFieldId, 'viewtype': 'edit' },0);
        }else if(flag == "1"){  //作废
            Modal.confirm({
                title: getLabel(15172,'系统提示'),
                content:  getLabel(83690,'您确认要作废该入库申请吗?'),
                onOk() {
                    cptInstockCheckStore.doDeleteInstock({ 'instockid': record.randomFieldId, 'viewtype': 'view' });
                },
                onCancel() { },
            });
        }

    }

    reRenderColumns(columns){
        const {cptInstockCheckStore} = this.props;
        columns.forEach(c=>{
            if(c.dataIndex=='tmpid'){
                c.render = function(text, record){
                    let valueSpan = record[c.dataIndex + "span"] !== undefined ? record[c.dataIndex + "span"] : record[c.dataIndex];
                    return <a onClick={()=>{cptInstockCheckStore.showInstockCheckInfo(true,{ 'instockid': record.tmpid, 'viewtype': 'edit' },0);}}>{valueSpan}</a>
                }
            } else {
              return c;
            }
        })
        return columns;
    }


}

export default CheckLisk;